package com.leokok.jts.learning.jts.core.algorithm;

import org.junit.Test;
import org.locationtech.jts.algorithm.MinimumDiameter;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

/**
 * 计算最小半径
 */
public class MinimumDiameterTest {

    /**
     * 返回最小外接矩形
     * @throws ParseException
     */
    @Test
    public void getMinimumRectangle() throws ParseException {
        WKTReader wktReader = new WKTReader();
        Geometry geometry = wktReader.read("POLYGON ((115.927044 31.988989, 115.9269865 31.9889405, 115.927013 31.9888955, 115.9270665 31.9888805, 115.9271465 31.9889025, 115.927182 31.988952, 115.927185 31.988998, 115.927115 31.9890265, 115.927067 31.989039, 115.927044 31.988989))");
        System.out.println(MinimumDiameter.getMinimumRectangle(geometry).toText());
    }

    /**
     * 获取最小半径
     * @throws ParseException
     */
    @Test
    public void getMinimumDiameter() throws ParseException {
        WKTReader wktReader = new WKTReader();
        Geometry geometry = wktReader.read("POLYGON ((115.927044 31.988989, 115.9269865 31.9889405, 115.927013 31.9888955, 115.9270665 31.9888805, 115.9271465 31.9889025, 115.927182 31.988952, 115.927185 31.988998, 115.927115 31.9890265, 115.927067 31.989039, 115.927044 31.988989))");
        System.out.println(MinimumDiameter.getMinimumDiameter(geometry).toText());
    }
}
